import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),

    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    // redirect: "/species-library",
    redirect: "/plant-library",
    meta: { title: "物种库", icon: "el-icon-s-data" },

    children: [
      {
        path: "plant-library",
        component: () => import("@/views/SpeciesLibrary/PlantLibrary/index"),
        name: "Plant-Library",
        meta: { title: "植物库", },
      },
      {
        path: "PlantAdd/:data?", // 编辑时的动态路由参数，用于传递植物ID
        name: "PlantAdd",
        component: () =>
          import("@/views/SpeciesLibrary/PlantLibrary/PlantAdd/index.vue"),
      },
      {
        path: "animal-library",
        component: () => import("@/views/SpeciesLibrary/AnimalLibrary/index"),
        name: "AnimalLibrary",
        meta: { title: "动物库", },
      },
      {
        path: "AnimalEdit/:data?", // 编辑时的动态路由参数，用于传递动物ID
        name: "AnimalEdit",
        component: () =>
          import("@/views/SpeciesLibrary/AnimalLibrary/AnimalEdit/index.vue"),
      },
    ],
  },

  {
    // path: "/",
    path: "/data-management/sample-info",
    // path: '/data-management',
    component: Layout,
    redirect: "/data-management/sample-info",
    // redirect: "/sample-info",
    meta: { title: "监测数据管理", icon: "el-icon-s-platform" },
    children: [
      {
        path: "sample-info",
        name: "SampleInfo",
        component: () => import("@/views/SampleInfo/index"),
        meta: { title: "样地信息", icon: "tree" },
        children: [],
      },
      {
        path: "edit/:id?", // 这里使用动态路由参数 id
        name: "EditPage",
        component: () => import("@/views/SampleInfo/EditPage/index.vue"),
        // meta: { title: '编辑录入' }
      },
    ],
  },
  {
    path: "/species-management",
    component: Layout,
    meta: { title: "调查样点数据管理", icon: "el-icon-eleme" },
    children: [
      // {
      //   path: "plant-basic-info",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Plant/BasicInfo.vue"),
      //   name: "Plant-Basic-Info",
      //   meta: { title: "植物基本信息" },
      // },

      //     // {
      //     //   path: "plant-survey-points",
      //     //   component: () =>
      //     //     import("@/views/SpeciesManagement/Plant/SurveyPoints.vue"),
      //     //   name: "Plant-Survey-Points",
      //     //   meta: { title: "植物调查样点" },
      //     //   // children:[

      //     //   // ]

      // },
      {
        path: "plants-add/:data?", // 这里使用动态路由参数 id
        name: "plants-add",
        component: () => import("@/views/SpeciesManagement/Plant/Add/index.vue"),
      },
      // {
      //   path: "plant-distribution",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Plant/Distribution.vue"),
      //   name: "Plant-Distribution",
      //   meta: { title: "植物分布" },
      // },
      // ... 其他植物相关子菜单
      // {
      //   path: "mammal-basic-info",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Mammal/BasicInfo.vue"),
      //   name: "Mammal-Basic-Info",
      //   meta: { title: "哺乳动物基本信息" },
      // },
      {
        path: "plant-survey-points",
        component: () =>
          import("@/views/SpeciesManagement/Plant/SurveyPoints.vue"),
        name: "Plant-Survey-Points",
        meta: { title: "植物调查样点", category: "01" },
      },
      {
        path: "animal-survey-points",
        component: () =>
          import("@/views/SpeciesManagement/Mammal/SurveyPoints.vue"),
        name: "Animal-Survey-Points",
        meta: { title: "动物调查样点", category: "02" },
      },
      {
        path: "mammal-add/:data?", // 这里使用动态路由参数 id
        name: "mammal-add",
        component: () =>
          import("@/views/SpeciesManagement/Mammal/Add/index.vue"),
      },
      // {
      //   path: "mammal-survey-points",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Mammal/SurveyPoints.vue"),
      //   name: "Mammal-Survey-Points",
      //   meta: { title: "哺乳动物调查样点", category: "01" },
      // },
      // {
      //   path: "mammal-add/:data?", // 这里使用动态路由参数 id
      //   name: "mammal-add",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Mammal/Add/index.vue"),
      // },
      // {
      //   path: "mammal-distribution",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Mammal/Distribution.vue"),
      //   name: "Mammal-Distribution",
      //   meta: { title: "哺乳动物分布" },
      // },
      // ... 其他哺乳动物相关子菜单
      // {
      //   path: "bird-basic-info",
      //   component: () => import("@/views/SpeciesManagement/Bird/BasicInfo.vue"),
      //   name: "Bird-Basic-Info",
      //   meta: { title: "鸟类基本信息" },
      // },
      // {
      //   path: "bird-survey-points",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Bird/SurveyPoints.vue"),
      //   name: "Bird-Survey-Points",
      //   meta: { title: "鸟类调查样点", category: "02" },
      // },
      // {
      //   path: "bird-add/:data?", // 这里使用动态路由参数 id
      //   name: "bird-add",
      //   component: () => import("@/views/SpeciesManagement/Bird/Add/index.vue"),
      // },

      // {
      //   path: "fish-survey-points",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Fish/SurveyPoints.vue"),
      //   name: "Fish-Survey-Points",
      //   meta: { title: "鱼类调查样点", category: "03" },
      // },
      // {
      //   path: "fish-add/:data?", // 这里使用动态路由参数 id
      //   name: "fish-add",
      //   component: () => import("@/views/SpeciesManagement/Fish/Add/index.vue"),
      // },
    ],
  },
  {
    // path: "/",
    path: "/SpeciesDistribution",
    // path: '/data-management',
    component: Layout,
    redirect: "/SpeciesDistribution",
    // redirect: "/sample-info",
    meta: { title: "物种分布", icon: "el-icon-s-help" },
    children: [
      {
        path: "ZwDistribution",
        component: () =>
          import("@/views/SpeciesDistribution/ZwDistribution/ZwDistribution.vue"),
        name: "ZwDistribution",
        meta: { title: "植物分布" },
      },
      {
        path: "DwDistribution",
        component: () =>
          import("@/views/SpeciesDistribution/DwDistribution/DwDistribution.vue"),
        name: "DwDistribution",
        meta: { title: "动物分布" },
      },
      // {
      //   path: "insect-survey-points",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Insect/SurveyPoints.vue"),
      //   name: "Insect-Survey-Points",
      //   meta: { title: "节肢动物调查样点", category: "04" },
      // },
      // {
      //   path: "insect-add/:data?", // 这里使用动态路由参数 id
      //   name: "insect-add",
      //   component: () =>
      //     import("@/views/SpeciesManagement/Insect/Add/index.vue"),
      // },
      // {
      //   path: "/species-distribution", // 路由路径
      //   component: () =>
      //     import("@/views/SpeciesManagement/SpeciesDistribution/index.vue"), // 组件的懒加载
      //   name: "SpeciesDistribution", // 路由名称
      //   meta: { title: "物种分布统计" }, // 路由元信息
      // },

      // ... 其他节肢动物相关子菜单
    ],
  },
  {
    path: "/user-management",
    component: Layout,
    // redirect: "/ground-monitoring/sample-info",
    // meta: { title: "用户管理", icon: "el-icon-user-solid" },

    children: [
      {
        path: "/user-management",
        name: "user-management",
        component: () => import("@/views/UserManagement/index.vue"),
        meta: { title: "用户管理", icon: "el-icon-user-solid" },
      },
    ],
  },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
